package cn.wolfcode.trip.base.service.impl;

import cn.wolfcode.trip.base.domain.Question;
import cn.wolfcode.trip.base.mapper.QuestionMapper;
import cn.wolfcode.trip.base.query.QueryObject;
import cn.wolfcode.trip.base.query.QuestionQueryObject;
import cn.wolfcode.trip.base.service.IQuestionService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.aspectj.weaver.patterns.TypePatternQuestions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class QuestionServiceImpl implements IQuestionService{
    @Autowired
    private QuestionMapper questionMapper;

    @Override
    public PageInfo queryByUserId(QueryObject qo) {
        //分页
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize(),qo.getOrderBy());
        //查Question
        List <Question> list = questionMapper.selectByUserId(qo);

        return new PageInfo(list);
    }

    @Override
    public List<Question> selectByUserId(Long userId) {
        return null;
    }

    //查询特定的问题
    @Override
    public Question selectById(Long id) {
        Question question = questionMapper.selectByPrimaryKey(id);
        return question;
    }
    //查询已回答问题
    @Override
    public PageInfo<Question> queryHasAnswer(QuestionQueryObject qo) {
        //分页
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize(),qo.getOrderBy());
        List<Question> list = questionMapper.selectHasAnswer(qo);
        return new PageInfo<>(list);
    }
    //查询没回答问题
    @Override
    public PageInfo<Question> queryNoAnswer(QuestionQueryObject qo) {
        //分页
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize(),qo.getOrderBy());
        List<Question> list = questionMapper.selectNoAnswer(qo);

        return new PageInfo<>(list);
    }
    //新增问题
    @Override
    public void save(Question question) {
        questionMapper.insert(question);
    }
    //关键字查询
    @Override
    public PageInfo<Question> queryKeyword(QuestionQueryObject qo) {
        //分页
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize(),qo.getOrderBy());
        List<Question> list = questionMapper.selectByKeyword(qo);
        return new PageInfo<>(list);
    }
}
